package com.hyb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyb.entity.Plan;
import com.hyb.mapper.PlanMapper;
import com.hyb.service.PlanService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  销售计划Service接口实现类
 * </p>
 *
 * @author hyb
 * @since 2021-12-29
 */
@Service
public class PlanServiceImpl extends ServiceImpl<PlanMapper, Plan> implements PlanService {

    @Autowired
    private PlanMapper planMapper;

    @Override
    public void createPlan(Plan plan) {
        planMapper.insert(plan);
    }

    @Override
    public List<Plan> getPlansBySaleId(Integer saleId) {
        QueryWrapper<Plan> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sale_id",saleId);
        queryWrapper.select("plan_id","sale_id","plan_date","plan_content","plan_result");
        return planMapper.selectList(queryWrapper);
    }

    @Override
    public List<Plan> getNotNullPlanResultBySaleId(Integer saleId) {
        return planMapper.selectNotNullPlanResultBySaleId(saleId);
    }

    @Override
    public List<Plan> getIsNullPlanResultBySaleId(Integer saleId) {
        List<Plan> plans = planMapper.selectIsNullPlanResultBySaleId(saleId);
        return plans;
    }

    @Override
    public void updatePlanResult(Plan plan) {
        planMapper.updateById(plan);
    }
}
